package com.sfdcj.se.meta.field;

import java.util.HashMap;

import com.sforce.soap._2006._04.metadata.CustomField;

public class MasterDetailType extends FieldType {

	static final String TYPE = "MasterDetail";

	public String referenceTo;

	public String relationshipLabel;

	public String relationshipName;

	public MasterDetailType() {
		super();
	}

	public void appendXML() {
		buf.append("<referenceTo>" + referenceTo + "</referenceTo>");
		buf.append("<relationshipLabel>" + relationshipLabel
				+ "</relationshipLabel>");
		buf.append("<relationshipName>" + relationshipName
				+ "</relationshipName>");
		buf.append("<relationshipOrder>0</relationshipOrder>");
		buf.append("<type>" + TYPE + "</type>");
	}

	@Override
	public String getTypeName() {
		return TYPE;
	}

	@Override
	public Object clone() {
		return new MasterDetailType();
	}

	@Override
	public void setAttributes(HashMap<String, String> attributes) {
		referenceTo = attributes.get("referenceTo");
		relationshipLabel = attributes.get("relationshipLabel");
		relationshipName = attributes.get("relationshipName");
	}

	@Override
	public CustomField toCustomField() {
		CustomField field = new CustomField();
		field.setFullName(objectFullname + "." + fullname);
		field.setLabel(label);
		field.setReferenceTo(referenceTo);
		field.setRelationshipLabel(relationshipLabel);
		field.setRelationshipName(relationshipName);
		field.setType(com.sforce.soap._2006._04.metadata.FieldType.MasterDetail);
		return field;
	}	
}
